// pages/addAddress/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:'',
    mobile:'',
    address:'',
    remark:''

  },

  nameInput: function(e) {
    this.setData({
      name: e.detail.value
    })
  },
  
  mobileInput: function(e) {
    this.setData({
      mobile: e.detail.value
    })
  },
  
  addressInput: function(e) {
    this.setData({
      address: e.detail.value
    })
  },
  
  remarkInput: function(e) {
    this.setData({
      remark: e.detail.value
    })
  },

  addAddress: function() {

    var token = wx.getStorageSync('token');
    var user = wx.getStorageSync('user');
    var that = this;
    wx.request({
      url: 'http://127.0.0.1:8080/system/address', // 添加地址接口
      method: 'post',
      header: {
        'content-type': 'application/json',  //这里注意POST请求content-type是小写，大写会报错
        'Authorization': token
      },
      data: {
        address: that.data.address,
        mobile: that.data.mobile,
        name: that.data.name,
        remark: that.data.remark,
        userId: user.userId
      },
      success(res) {
        if (res.statusCode==200) {
          wx.showToast({
            title: "添加成功",
            icon: 'none',
          })
          var pages = getCurrentPages();
          var beforePage = pages[pages.length - 2];
          beforePage.onLoad(beforePage.options);
          wx.navigateBack({
            delta: 1,
          })
        }
      }
    })
  }
})